layui.config({
    base: '/js/base/module/'
}).extend({
    richTxtUtil: 'richTxtUtil',
    fileUtil: 'fileUtil',
    dialogUtil: 'dialogUtil',
    dateUtil: 'dateUtil',
    checkUtil: 'checkUtil',
    dtreeUtil: 'dtreeUtil',
    pageUtil: 'pageUtil',
    treeGrid: 'treeGrid',
    baseUtil:'baseUtil'
});

layui.use(['form', 'jquery', 'table', 'baseUtil', 'dialogUtil', 'pageUtil', 'fileUtil'], function () {
    var form = layui.form,
        baseUtil = layui.baseUtil,
        fileUtil = layui.fileUtil,
        dialogUtil = layui.dialogUtil,
        pageUtil = layui.pageUtil,
        table = layui.table,
        $ = layui.jquery;

    $(".imageShow").click(function () {
        fileUtil.imageSingleShow($(this).attr("data-show-path"));
    })
    /**
     * 工具栏-增加弹窗
     */
    $('#tool .addBtn').click(function () {
        var url = $(this).attr('data-url');
        var title = $(this).attr('data-title');
        var width = $(this).attr('data-width');
        var height = $(this).attr('data-height');
        dialogUtil.popUp(title,url, function (layer, index) {
            var body = layui.layer.getChildFrame('body', index);
            body.find("#save").bind("click", function () {
                parent.layer.closeAll();
                location.reload();
            });
        },width,height);
        return false;
    });

    /**
     * 工具栏-tab跳转
     */
    $('#tool .jumpTabBtn').click(function () {
        var url = $(this).attr('data-url');
        var tabName = $(this).attr('data-tab-name');
        var id = $(this).attr('data-id');
        parent.tab(id, url, tabName);
    });

    /**
     * 工具栏-当前页面跳转
     */
    $('#tool .jumpBtn').click(function () {
        var url = $(this).attr('data-url');
        window.location.href = url;
        return false;
    });

    /**
     * 工具栏-删除
     */
    $('#tool .deleteBtn').click(function () {
        var url = $(this).attr('data-url');
        var ids = pageUtil.checkBoxCheckedIds();
        if (ids != null) {
            page.delete(url, {"id": ids, "_method": "DELETE"}, "您确定要删除选中项吗？", function (data) {
                table.reload("entityList", {
                    where: {}
                });
            });
        }
        return false;
    });

    /**
     * 工具栏-搜索
     */
    form.on('submit(seacherBtn)', function (data) {
        table.reload("entityList", {
            where: data.field
        });
        return false;
    });

});
